package com.example.dormitorymanagement.CommonExceptionHandler;


import com.example.dormitorymanagement.exception.AbnormalPermissions;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String ExceptionHandler(HttpServletRequest request, HttpServletResponse response , Exception e)
    {
        if (e instanceof AbnormalPermissions)
        {

            return e.getMessage();

        }
        return null;
    }

}
